<%--
  作者:张伟

  联系:adamzzww@163.com
  时间:2016-11-30
  说明:角色权限分配
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑角色信息</title>
    <%@include file="../../desktop/include/assets.jsp" %>
    <script type="text/javascript" src="<%=_asset_path%>/layer/layer.js"></script>
    <%
        String url = request.getContextPath() + Global.PATH;
    %>

    <style>
        .infoForm {
            padding: 20px
        }
    </style>
</head>
<body>
<div class="infoForm">
    <form id="editForm" name="editForm" class="form-horizontal form-condensed" role="form" method="post"
          action="<%=url%>/role">
        <div class="form-group">
            <label class="col-xs-3 control-label required" for="roleName">角色名称</label>
            <div class="col-xs-6">
                <input type="text" name="roleName" id="roleName" value="${entity.roleName}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">权限分配</label>
            <div class="col-xs-6">
                <input type="hidden" name="menusId" id="menusId" value="${menusId}">
                <input type="text" name="menusName" id="menusName" value="${menusName}" readonly
                       style="width:60%;display:inline;margin-right: 10px;" class="form-control">
                <a id="menuSel" class="btn"><i class="icon-search">选择</i></a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">备注</label>
            <div class="col-xs-6">
                <textarea rows="5" class="form-control" id="remark" name="remark">${entity.remark}</textarea>
            </div>
        </div>
        <hr/>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" id="saveBtn" class="btn btn-primary" value="保存" data-loading="稍候...">
                <c:if test="${!empty entity.roleId }">
                    <input type="hidden" name="roleId" value="${entity.roleId}">
                </c:if>
            </div>
        </div>
    </form>
</div>

<script>

    $(function () {

        $("#selAll").click(function () {
            $("[name='monitorPage']:checkbox").attr("checked", "true");
        });

        //权限选择
        $('#menuSel').on('click', function () {
            layer.open({
                type: 2,
                title: '选择菜单功能',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['auto', ($(window).height() - 100) + 'px'],
                content: '<%=url%>/menu/treeframe?roleId=${entity.roleId}'
            });
        });

        var validate = $("#editForm").validate({
            //debug: true, //调试模式取消submit的默认提交功能
            rules: {
                roleName: {
                    required: true,
                }
            },
            messages: {
                roleName: {
                    required: "请输入角色名"
                }
            },
            submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                $.ajax({
                    url: form.action,
                    type: form.method,
                    data: $(form).serialize(),
                    success: function (data) {
                        // 提交表单
                        if (data == "success") {
                            alert("提交成功！");
                            //$("#editForm")[0].reset();
                            window.parent.location.reload();
                        } else {
                            alert("提交失败！");
                        }
                    }
                });
            },
        });
    });
</script>

</body>
</html>
